package view.diaLogView;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.TextView;

import com.example.administrator.text.R;

/**
 * Created by Administrator on 2016/6/30.
 * 网络操作时的提示框
 */
public class UploadDialog extends Dialog{
    private Context mContext;
    private String mName;
    private TextView textView;
    private static UploadDialog mUploadDialog;

    @Override
    public void show() {
      Window window = getWindow();
      window.setGravity(Gravity.BOTTOM);
      super.show();
   }

    /**
     * 实例化
     * @return
     */
    public static UploadDialog getInstance(Context context,String name){
        if(mUploadDialog == null){
            mUploadDialog = new UploadDialog(context,name);
        }
        return mUploadDialog;
    }

    /**
     * 设置内容，及show
     */
    public void getStringShow(String name){
        textView.setText(name);

    }

    protected UploadDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    public UploadDialog(Context context,String name) {
        super(context, R.style.upoad_dialog);
        this.mContext = context;
        Log.e("Name"," UploadDialog "+name);
        this.mName = name;
    }

    @Override protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        init();
    }

    private void init() {
        ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        params.width = mContext.getResources().getDisplayMetrics().widthPixels;
        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View mView = inflater.inflate(R.layout.upoad_dialog, null);
        textView = (TextView) mView.findViewById(R.id.text_upload);
        Log.e("Name"," init "+mName);
        textView.setText(mName);
        setContentView(mView, params);
    }

}
